<template>
  <c-form-dialog
    label-width="140px"
    title="编辑通知公告"
    ref="form"
    :table-name="tableName"
    :form-items="formItems"
    :form-data="formData"
    :before-save="handleBeforeSave"
    :table-id="tableId"
    @close="beforeClose"
    @success="handleSuccess"
    :visible.sync="innerVisible"
  ></c-form-dialog>
</template>

<script>
import { mapGetters } from 'vuex'
import WangEditor from '@/components/WangEditor'
export default {
  components: {},
  props: {
    visible: Boolean,
    tableId: String,
    formData: { type: Object, default: () => ({}) },
  },
  data() {
    return {
      innerVisible: false,
      tableName: 'notice_placard',
      formItems: [
        {
          tag: 'input',
          itemAttrs: {
            label: '标题',
            rules: [{ required: true, message: '请输入通知公告标题', trigger: 'blur' }],
          },
          attrs: { key: 'notice_placard_title', value: '', placeholder: '请输入通知公告标题' },
        },
        {
          tag: WangEditor,
          itemAttrs: {
            label: '内容',
            rules: [{ required: true, message: '请输入通知公告内容', trigger: 'blur' }],
          },
          attrs: {
            key: 'content',
            value: '',
            style: 'height:500px; padding-bottom: 30px;',
          },
        },
        {
          tag: 'upload',
          itemAttrs: { label: '附件: ' },
          attrs: {
            key: 'attachment',
            value: '',
            accept: '',
            fileName: 0,
            listType: '',
            dir: '/credit/notice',
          },
          getAttrs: () => ({ dir: `/credit/notice/${this.userId}` }),
        },
      ],
    }
  },
  computed: {
    ...mapGetters(['clientId', 'userId']),
  },
  watch: {
    visible(val) {
      this.innerVisible = val
    },
  },

  created() {},
  methods: {
    handleBeforeSave(data) {
      data.service_id = this.clientId
      return data
    },
    handleSuccess() {
      this.$emit('success', true)
    },
    beforeClose() {
      this.$emit('update:visible', false)
    },
  },
}
</script>
<style lang="scss" scoped></style>
